;(function($){
	$.fn.xsxm_out = function(opts){
		var el = this;
		var opt = {
			xsxm_jdh_array:[],
			brzd_array:[],
			pageTh:'',
			dataBack : function(){},
			closeBack : function(){},
		}
		var param = $.extend(opt,opts);
		var app = new App(el,param);
	}
	
	var App = function(el,param){
		this.el = el;
		this.param = param;
		var t = this;
		t.initHtml();
		t.appendData();
		t.bindEvent();
	}
	
	App.prototype = {
		bindEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			//返回
			el.find("#modalBtnBack").click(function(){
				param.closeBack();
				el.modal("hide");
				el.empty();
			})
			
		},
		initHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			
			
			

			el.addClass("modal").attr("tabindex","-2").attr("data-backdrop","static");
    		var html=	'<div id="xsxm_out" class="modal-dialog" style="width:1024px;overflow-y: auto;">'+
				    		'<div id="pageOverlay" class="hide"></div>'+
							'<div id="loading" class="loading hide">	'+
								'<i class="ace-icon fa fa-spinner fa-spin orange bigger-250"></i>'+
							'</div>'+
							'<div class="modal-content">'+
					  			'<div class="modal-header no-padding">'+
									'<div class="table-header">'+
										'<button id="close-dialog" type="button" class="close" data-dismiss="modal" aria-hidden="true" value="HTML">'+
											'<span class="white">&times;</span>'+
										'</button>'+
										'<span id="modal-h4">'+$.i18n.propJsp("已结账单")+'</span>'+
									'</div>'+
								'</div>'+
								'<div id="xsxmTh_out_container" class="modal-body" style="height:600px;">'+
										
								'</div>'+				
								'<div class="modal-footer">'+
									'<div class="clearfix">'+
										'<div class="pull-right">'+
//											'<button id="modalBtnCheck" class="btn btn-info btn-sm data-dismiss="modal">'+
//												'<i class="ace-icon fa fa-check"></i>'+$.i18n.propJsp("确定")+
//											'</button>'+
											'<button id="modalBtnBack" class="btn btn-default btn-sm" data-dismiss="modal">'+
												'<i class="ace-icon fa fa-undo"></i>'+$.i18n.propJsp("返回")+
											'</button>'+
										'</div>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>';
    		el.html(html);
    		
    		var csstext = 	'<style>'+
								'.rightXsxmTitle_out{cursor: pointer;width:80px;display:flex;flex-direction:column;align-items:center;font-size:16px;background:#ededed;border-bottom: 1px solid #f5f5f5;margin:0px auto;}'+
								'.rightXsxmTitleSpan_out{word-break:break-all;line-height: 17px;color:#2b8ccc;}'+
								'.right_xsxm_box_out{cursor: pointer;float: left;border: 1.5px solid #e2d8d8;border-radius: 3px;position: relative;margin:0px 2px 2px 0px;height: auto;padding: 4px 5px;}'+
								'.right_xsxm_box_out.active{border: 1.5px solid #2b8ccc;}'+
								'.right_xsxm_box_out_line1,.right_xsxm_box_out_line2,.right_xsxm_box_out_line3{height: 100%;float:left;margin-right:10px;}'+
								'.mainTh_out{border:1px solid white;border-radius: 5px;padding: 0px 2px;}'+
							'</style>';
			$(csstext).appendTo("#xsxm_out")
		},
		appendData:function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			$.each(param.brzd_array,function(key,value){
				var handpanel_info = JSON.parse(value.handpanel_info)
				var class_extend = ""
				if(param.pageTh==value.th){
					class_extend = "mainTh"
				}
				var ico_info = JSON.parse(value.ico_info)
				var ico_info_text = ""
					$.each(ico_info,function(key,value){
						if(JSON.stringify(value)!="{}"){
							ico_info_text += getTextStyle(value);
						}
					})
				var th = '<span class="" style="">'+value.th+'</span>';
				var je = '<span class="" style="">'+value.xfje+'</span>';
				if(el.find(".xsxmTh_box_out[data-no='"+value.no+"']").size()<=0){
					var html = 	'<div class="xsxmTh_box_out" data-no="'+value.no+'" data-th="'+value.th+'" data-mess="'+encodeURIComponent(JSON.stringify(value))+'" style="display:flex !important;margin-bottom:4px;border-bottom: 1px solid #E8E8E8;">'+
									'<div class="rightXsxmTitle_out" style="height:60px;width:100px;background:'+handpanel_info.bgcolor+' !important;overflow: hidden;border: 1px solid '+handpanel_info.bgcolor+';">'+
										'<div class="line1" style="width: 100%;height:20px;line-height: 20px;float: left;">'+
											'<span class="span_th '+class_extend+'" style="color:'+handpanel_info.tcolor+' !important;font-size: 13px;">'+th+'</span>'+
											'<small class="text-muted" style="color:'+handpanel_info.tcolor+' !important; font-size:60%;  float:right;">'+
												ico_info_text+
											'</small>'+
										'</div>'+
										'<div class="line2" style="width: 100%;height:20px;line-height: 20px;float: left;text-align: right;">'+
											'<span style="color:'+handpanel_info.tcolor+' !important;font-size: 13px;">'+je+'</span>'+
										'</div>'+
										'<div class="line3" style="width: 100%;height:20px;line-height: 20px;float: left;text-align: right;position:relative;padding-left:0px;">'+
										'</div>'+
										
									'</div>'+
									'<div class="xsxmLine_out clearfix" data-xsxm_no="xsxm_'+value.no+'" style="flex:1;padding-left:2px">'+
									'</div>'+
								'<div>';
					el.find("#xsxmTh_out_container").append(html)
				}
			})
			
			$.each(param.xsxm_jdh_array,function(key,value){
				if(el.find(".xsxmTh_box_out[data-no='"+value.no+"']").size()>0){
					var mess_old = JSON.parse(decodeURIComponent(el.find(".xsxmTh_box_out[data-no='"+value.no+"']").attr("data-mess")))
					var mess_new = JSON.stringify(value)
					el.find(".xsxmTh_box_out[data-no='"+value.no+"']").attr("data-mess",encodeURIComponent(JSON.stringify($.extend(JSON.parse(mess_new),mess_old))))
				}
				
				var info = JSON.parse(value.info)
				var info_text = ""
				$.each(info,function(key,value){
					if(JSON.stringify(value)!="{}"){
						info_text += getTextStyle(value);
					}
				})
				
				var panel_info =  JSON.parse(value.panel_info)
				var bgcolor = (panel_info['bgcolor']?panel_info['bgcolor']:"white")
				var tcolor = (panel_info['tcolor']?panel_info['tcolor']:"")
				
				
				var xsxmhtml = 	'<div class="right_xsxm_box_out" data-sort="'+value.sort+'" data-bh="'+value.bh+'" data-xh="'+value.xh+'" data-th="'+value.ct_brzd_th+'"  data-mess="'+encodeURIComponent(JSON.stringify(value))+'" style="background-color:'+bgcolor+';color:'+tcolor+';">'+
									'<div class="right_xsxm_box_out_line3" style="display: flex;">'+
										info_text+
									'</div>'+
								'</div>';
				el.find(".xsxmLine_out[data-xsxm_no='xsxm_"+value.no+"']").append(xsxmhtml)
				
			})
		},
	}
	
})(jQuery)